add a set of apis to configure wasi-nn via InstantiationArgs2#4764
add a set of apis to configure wasi-nn via InstantiationArgs2#4764zhanheng1 wants to merge 28 commits intobytecodealliance:mainfrom
Conversation
77794ae to
c73e4aa
Compare
| #include "wasi_nn.h" | ||
|
|
||
| #undef WASM_ENABLE_WASI_EPHEMERAL_NN | ||
| #undef WASI_NN_NAME |
There was a problem hiding this comment.
In wasi_ephemeral_nn.h, macros are defined and then wasi_nn.h is included immediately after, but these macro definitions are later undefined (#undef). This means that in utils.h, the macros might be in an undefined state, leading to compilation errors( if WASM_ENABLE_WASI_EPHEMERAL_NN != 0).
There was a problem hiding this comment.
wasi_ephemeral_nn.h header is meant to be used by applications which uses this version of api.
these macros are not meant to be used by applications. (WASM_ENABLE_WASI_EPHEMERAL_NN, WASI_NN_NAME, WASI_NN_ERROR_TYPE, etc)
they are supposed to use eg. wasi_ephemeral_nn_error.
see samples like wamr-wasi-extensions/samples/nn-cli/main.c
… named WASINNRegistry. Replace malloc/free to wasm_runtime_malloc/_free, replace strdup to bh_strdup.
| /opt/wasi-sdk/bin/clang \ | ||
| --target=wasm32-wasi \ | ||
| -DWASM_ENABLE_WASI_NN=1 \ | ||
| -DWASM_ENABLE_WASI_EPHEMERAL_NN=1 \ |
There was a problem hiding this comment.
why do you enable WASM_ENABLE_WASI_EPHEMERAL_NN for this, but not for test_tensorflow_quantized.c the below?
have you run these tests at all?
if not, i'd suggest to leave these to use the legacy api for now.
There was a problem hiding this comment.
why do you enable WASM_ENABLE_WASI_EPHEMERAL_NN for this, but not for test_tensorflow_quantized.c the below?
Just forgot to enable them for test_tensorflow_quantized.c, thanks.
have you run these tests at all?
Yes, I have tested them all with WASM_ENABLE_WASI_EPHEMERAL_NN enabled.
| const uint32_t **encoding, | ||
| const uint32_t **target, | ||
| uint32_t n_graphs, | ||
| const char **graph_paths); |
There was a problem hiding this comment.
i suppose these should be in wasm_export.h as it's used by the embedding applications like iwasm.
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_set_wasi_nn_registry(wasm_module_inst_t module_inst, | ||
| struct WASINNRegistry *wasi_ctx); |
There was a problem hiding this comment.
wasm_runtime_get_wasi_nn_registry/wasm_runtime_set_wasi_nn_registry are not supposed to be used by applications, are they?
i guess they should not be in wasm_export.h.
in wasm_export.h, put only api which is used directly by application. (eg. iwasm)
internal api should go to somewhere else, like wasm_runtime_common.h
|
|
||
| WASM_RUNTIME_API_EXTERN void | ||
| wasm_runtime_set_wasi_nn_registry(WASMModuleInstanceCommon *module_inst_comm, | ||
| WASINNRegistry *wasi_nn_ctx); |
There was a problem hiding this comment.
two duplicated wasm_runtime_set_wasi_nn_registry prototypes in this file.
|
|
||
| #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 | ||
| wasm_runtime_wasi_nn_registry_create(&nn_registry); | ||
| wasi_nn_set_init_args(inst_args, nn_registry, &wasi_nn_parse_ctx); |
There was a problem hiding this comment.
wasi_nn_set_init_args vs inst_args look a bit confusing.
maybe you meant wasi_nn_set_inst_args?
add a set of apis to configure wasi-nn via InstantiationArgs2: